package com.easyticket.system.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.easyticket.common.dao.EntityDao;
import com.easyticket.system.pojo.User;
import com.easyticket.system.service.UserService;

@Service("userService")
public class UserServiceImpl implements UserService {
	
	protected Logger log = LoggerFactory.getLogger(getClass());
	
	@Resource(name = "entityDao")
	private EntityDao<User, String> entityDao;
	
	public void save(User user) {
		entityDao.save(user);
	}

	public void delete(User user) {
		entityDao.delete(user);
	}
	
	public void delete(int id) {
		// TODO Auto-generated method stub
		
	}

	public User get(int id) {
		// TODO Auto-generated method stub
		return null;
	}

	public List<User> query() {
		// TODO Auto-generated method stub
		return null;
	}

	public void update(User user) {
		// TODO Auto-generated method stub
		
	}

	public void updateTransfer(String str1, String str2) {
		User user = entityDao.load(User.class, str1);
		user.setPassword("OK");
		entityDao.update(user);
		User user1 = entityDao.load(User.class, str2);
		user1.setPassword("ON");
		entityDao.update(user1);
	}
	
	@SuppressWarnings("unchecked")
	public boolean checkLogin(User user) {
        String hql = "from User u where u.userName = ? and u.password = ?";
        List findlist = entityDao.createQuery(hql, user.getUserName(), user.getPassword()).list();
        if (findlist.size()>0) {
            return true;
        }
        return false;    
	}
	
	public EntityDao<User, String> getEntityDao() {
		return entityDao;
	}
	
	public void setEntityDao(EntityDao<User, String> entityDao) {
		this.entityDao = entityDao;
	}

}